/*
 * @(#)ButtonPanelRIP.java     Didier Gutacker
 *
 */

/** 
 * Die Klasse ButtonPanelRIP stellt die zusaetzlchen Tasten fuer die Simulation des RIP-Algorithmus
 * zu Verfuegung. Sie ist eine graphische Komponente der Klasse SimFrameRIP.
 *
 * @author 	Didier Gutacker
 * @version     1.0, 06.09.1997
 * @see SimFrameRIP
 * @see ButtonPanel 
 * @see NetworkRIP
 * @see NetworkCanvasRIP
 * @see TextMethods
 *
 */

import java.awt.*;
import java.lang.*;


final class ButtonPanelRIP extends ButtonPanel {

   public NetworkCanvasRIP canvas;
 
   private NetworkRIP net;
   private Button disableNodeButton;
   private Button enableNodeButton;

  /**
   * Konstruktor
   */

  ButtonPanelRIP( TextMethods text ) {
    DEBUG = new debug();
    setLayout( new GridLayout( 3, 3 ) );
    this.text = text;

    addNodeButton = new Button( text.buttonPanel_addNodeButtonText );
    removeNodeButton = new Button( text.buttonPanel_removeNodeButtonText );
    removeNodeButton.disable();

    addLinkButton = new Button( text.buttonPanel_addLinkButtonText );
    addLinkButton.disable();

    removeLinkButton = new Button( text.buttonPanel_removeLinkButtonText );
    removeLinkButton.disable();

    startSendingButton = new Button( text.buttonPanel_startSendingButtonText );
    startSendingButton.disable();

    stopSendingButton = new Button( text.buttonPanel_stopSendingButtonText );
    stopSendingButton.disable();

    inspectRoutingTableButton = new Button( text.buttonPanel_inspectRoutingTableButtonText );
    inspectRoutingTableButton.disable();

    continueButton = new Button( text.buttonPanel_continueButtonText );
    continueButton.disable();

    stopButton = new Button( text.buttonPanel_stopButtonText );

    disableNodeButton = new Button( text.buttonPanel_disableNodeButtonText );
    disableNodeButton.disable();

    enableNodeButton = new Button ( text.buttonPanel_enableNodeButtonText );
    enableNodeButton.disable();

    add( addNodeButton );
    add( removeNodeButton );
    add( inspectRoutingTableButton );

    add( addLinkButton );
    add( removeLinkButton );
    add( startSendingButton );

    add( stopSendingButton );
    add( continueButton );
    add( stopButton );

  } // ButtonPanelRIP.ButtonPanelRIP

  
  public final void initialize( NetworkRIP net ) {
    this.net = net;
    canvas = (NetworkCanvasRIP) net.getCanvas(); // ???????????
  } // ButtonPanel.initialize

  public boolean action( Event e, Object obj ) {

    if ( obj.equals( text.buttonPanel_stopButtonText ) ) {
      stopped = true;
      resetState();
      canvas.stopRequest();
    } else if ( obj.equals( text.buttonPanel_continueButtonText ) ) {
      stopped = false;
      resetState();
      canvas.continueRequest();
    } else if ( obj.equals( text.buttonPanel_addLinkButtonText ) ) {
      canvas.addLinkRequest();
      return true;
    } else if ( obj.equals( text.buttonPanel_addNodeButtonText ) ) {
      canvas.addNodeRequest();
      return true;
    } else if ( obj.equals( text.buttonPanel_removeNodeButtonText ) ) {
      canvas.removeNodeRequest();
    } else if ( obj.equals( text.buttonPanel_removeLinkButtonText ) ) {
      canvas.removeLinkRequest();
    } else if ( obj.equals( text.buttonPanel_startSendingButtonText ) ) {
      canvas.startSendingRequest();
    } else if ( obj.equals( text.buttonPanel_stopSendingButtonText ) ) {
      canvas.stopSendingRequest();
    } else if ( obj.equals ( text.buttonPanel_inspectRoutingTableButtonText ) ) {
      canvas.inspectRoutingTableRequest();
    } // if 
    return false;
  } // ButtonPanel.action


  /**
   * Setze den Status aller Buttons anhand des aktuellen Netzzustandes
   * @see Network
   */


  public void resetState() {
      if ( stopped ) {
      addNodeButton.disable();
    } else {
      addNodeButton.enable();
    } // if
    if ( net.getNumNodes() < 1 || stopped ) {
      addLinkButton.disable();
    } else {
      addLinkButton.enable();
    } // if
    if ( net.getNumLinks() == 0 || stopped ) {
      removeLinkButton.disable();
    } else {
      removeLinkButton.enable();
    } // if
    if ( net.getNumNodes() == 0 || stopped ) {
      removeNodeButton.disable();
    } else {
      removeNodeButton.enable();
    } // if
    if ( stopped ) {
      stopButton.disable();
      continueButton.enable();
    } else {
      continueButton.disable();
      stopButton.enable();
    } // if 
    if ( net.getNumNodes() == 0 || stopped ) {
      inspectRoutingTableButton.disable();
    } else {
      inspectRoutingTableButton.enable();
    } // if
    if ( net.getNumLinks() < 1 || stopped ) {
      startSendingButton.disable();
    } else {
      startSendingButton.enable();
    } // if
    if ( net.getNumSenders() == 0 || stopped ) {
      stopSendingButton.disable();
    } else {
      stopSendingButton.enable();
    } // if
  } // ButtonPanelRIP.setState    

  /**
   * Erneuere alle Buttonbezeichnungen 
   */

  public void redrawLabels( TextMethods text ) {
    super.redrawLabels(text);
    resetState(); 
    layout();
  } // ButtonPanelRIP.redrawLabels

  /**
   * Inaktiviert alle Buttons
   */

  void disableAll() {
    super.disableAll();
  } // ButtonPanelRIP.disableAll

} // ButtonPanelRIP














